<?php

namespace addons\mental\controller;

use app\common\controller\Api;
use \think\Config;
use think\Lang;

/**
 * api基类
 */
class Base extends Api
{
    protected $noNeedLogin = ['*'];// 无需登录即可访问的方法，同时也无需鉴权了
    protected $noNeedRight = ['*'];// 无需鉴权即可访问的方法

    public function _initialize()
    {
        check_cors_request();
        if (!isset($_COOKIE['PHPSESSID'])) {
            Config::set('session.id', $this->request->server("HTTP_SID"));
        }
        parent::_initialize();
        //设置用户信息输出字段
        $this->auth->setAllowFields(['id', 'bio', 'nickname', 'mobile', 'avatar', 'money', 'gender', 'score', 'email','cumulative_gain']);
        $config = get_addon_config('mental');
        Config::set('mental', $config);
        //加载当前控制器的语言包
        $controllername = strtolower($this->request->controller());
        Lang::load(ADDON_PATH . 'mental/lang/' . $this->request->langset() . '/' . str_replace('.', '/', $controllername) . '.php');
    }

}
